package common.dao.mysql;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import common.helper.toolkit.FileToolkit;

import java.io.IOException;

/**
 * Created by Common on 11/25/16.
 */

/*
https://github.com/FasterXML/jackson-dataformat-yaml
http://yaml.org/
 */
public class MySqlConf {
    public static class ConfInfo{
        public String host;
        public int port;
        public String user;
        public String pswd;
    }

    public static ConfInfo getMySqlConf(String yamlPath){
        String yamlStr = FileToolkit.readStringFromFile(yamlPath);
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        ConfInfo info = null;
        try {
            info = mapper.readValue(yamlStr, ConfInfo.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return info;
    }

}
